home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12153 < prev    next >
Encoding:
Text File  |  1996-08-05  |  929 b   |  37 lines

  1. Path: loki.tor.hookup.net!news
  2. From: Rajendra_Singh@msn.com (Rajendra Singh)
  3. Newsgroups: comp.lang.c
  4. Subject: Is This Bad Coding Practice?
  5. Date: Fri, 29 Mar 1996 16:19:03 GMT
  6. Organization: HookUp Communication Corporation, Oakville, Ontario, CANADA
  7. Message-ID: <4jgnt2$9d1@loki.tor.hookup.net>
  8. NNTP-Posting-Host: u36u400.tor.hookup.net
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. int main(int argc, char *argv[])
  12.    {
  13.    char string[128];
  14.    char *func1(void);
  15.  
  16.    strcpy(string, func1());
  17.    return 0;
  18.    }
  19.  
  20. char *func1(void)
  21.    {
  22.    char test[100];
  23.  
  24.    sprintf(test, "Test:  %d", 1);
  25.    return test;
  26.    }
  27.  
  28. ... since I am using the value returned from func1() immediately (in
  29. main()), is this reliable?  After I copy it into "string", I won't be
  30. using that area of memory anymore (i. e. the pointer returned by
  31. func1()).
  32.  
  33. ---
  34. Rajendra Singh, B. Sc. (Rajendra_Singh@msn.com)
  35. "What is understood need not be discussed." - Loren Adams
  36.  
  37.